package servlet.request.test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Administrator
 * @Date 2020/5/15 10:21
 * Get请求相关操作：
 * 获取get请求的url；请求头User-Agent；请求参数
 **/
@WebServlet("/getServlet")
public class GetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("获取get请求的url和请求方法：");
        StringBuffer requestURL=req.getRequestURL();
        String method =req.getMethod();
        System.out.println("获取请求头user-agent");
        String agent= req.getHeader("User-Agent");
        System.out.println("获取请求参数：");
        System.out.println("get请求的参数在url中的？后面");
        String name= req.getParameter("name");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
